import requests
import json
import time


appkey = 'dingxokazzgqz4k5ypbb'
appsecret = 'SP8sN9GK77Dmvuv_rmZLcZ8nbbuLX7DtHSjepJ4RaUXIxvdzvMPg0pF185_LPt0x'



dt_start = '2020-02-28 08:40:30'
dt_end = '2020-02-28 22:40:30'
ts_start = int(time.mktime(time.strptime(dt_start, "%Y-%m-%d %H:%M:%S"))) * 1000
ts_end = int(time.mktime(time.strptime(dt_end, "%Y-%m-%d %H:%M:%S"))) * 1000

print(ts_start,ts_end)

api_url = "https://oapi.dingtalk.com/gettoken?appkey=%s&appsecret=%s"%(appkey,appsecret)

def get_token():
    # try:
    res = requests.get(api_url)
    if res.status_code == 200:
        str_res = res.text
        token = (json.loads(str_res)).get('access_token')
        return token


token = get_token()

print(token)

#res = requests.get('https://oapi.dingtalk.com/checkin/record?access_token=%s&department_id=235636048&start_time=%s&end_time=%s&offset=0&size=100&order=asc' % (token,ts_start,ts_end))

res_all = requests.get('https://oapi.dingtalk.com/user/simplelist?access_token=244644611aed3b108c0da0d886b61318&department_id=235636048')

print(res_all.text)